<template>
  <div>
    <!-- 图表的容器 -->
    <div id="main" style="width: 800px; height: 400px"></div>
  </div>
</template>
<script>
import * as echarts from 'echarts'
import http from '../util/http'
export default {
  data () {
    return {
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  mounted () {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'))

    http('reports/type/1').then((res) => {
      // 合并对象
      const ress = Object.assign(this.options, res.data.data)
      console.log(ress)
      myChart.setOption(ress)
    })
  }
}
</script>
